package cn.test.app.a.controller;

import cn.ifloat.brick.sprofile.web.common.BasicController;
import cn.test.app.a.api.OrderApi;
import cn.test.app.a.domain.Ord;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 查询订单表数据 返回HTML页面
 * @author zhanghengtong
 */
@Controller
@RequestMapping("page")
public class OrderPageController extends BasicController {

    @Resource
    private OrderApi orderApi;

    @PostConstruct
    public void init() {
        System.err.println("case-console1 OrderPageController init");
    }

    /**
     * 订单列表页面
     *
     * @param model 模型
     * @return 列表页面
     */
    @RequestMapping("list")
    public String page(Model model) {
        List<Ord> list = orderApi.ordList();
        logger.info("list: " + list.size());
        model.addAttribute("list", list);
        return "order/page";
    }

    @RequestMapping(value = "test", consumes = {"text/plain", "application/*"})
    public void test(HttpServletResponse response) throws IOException {
//        response.setHeader("Content-Type", "application/json");
        response.getWriter().print("\n" +
                "{\"data\":{\"type\":\"\\u5f69\\u8679\\u5c41\",\"text\":\"\\u751f\\u6c14\\u5f52\\u751f\\u6c14\\uff0c\\u53c8\\u4e0d\\u662f\\u4e0d\\u559c\\u6b22\\u4f60\\u4e86\"}}");
    }

//    @PostMapping(value = "term", consumes = MediaType.APPLICATION_JSON_VALUE)
//    public List<Ord> list(@RequestBody Ord ord) {
//        return orderApi.list();
//    }
}
